function places_loading()
{	var HTMLOut = document.getElementById("outDiv").innerHTML;

	HTMLOut += "places loading!" + "<br>";
	document.getElementById('outDiv').innerHTML = HTMLOut;
	
	document.getElementById('textIn').focus();
}

var Place = new Object;
var NUM_PLCS = 0;

function makePlace(name,title,intro,description,sights,special,exits,hExits)
{
	Place[NUM_PLCS] = new Object;
	Place[NUM_PLCS].id = NUM_PLCS;
	Place[NUM_PLCS].name = name;
	Place[NUM_PLCS].title = title;
	Place[NUM_PLCS].intro = intro;
	Place[NUM_PLCS].description = description;
	Place[NUM_PLCS].sights = sights;
	Place[NUM_PLCS].special = special;
	Place[NUM_PLCS].exits = exits;
	Place[NUM_PLCS].hExits = hExits ? hExits : ""; // optional

	eval(name + " = Place[" + NUM_PLCS + "];");
	
	NUM_PLCS++;
}

makePlace("nowhere",
"NOWHERE",
"",
"This place doesn't exist!",
"",
"",
"");

makePlace("intersection",
"INTERSECTION",
"",
"[[startCab()]]You are on a busy street corner, near a newspaper stand.",
"north::The Veidt Tower dominates the skyline to the north.\
/south::To the south is a dark alleyway.\
/east::The way east leads to Daniel Dreiberg's house.\
/west::The docks are west from here.\
/newsstand|stand|kiosk::You often buy [iThe New Frontiersmani] there.\
/tower::Adrian Veidt's monument to his own ego is visible in the distance to the west.\
/comic|book|comics|freighter::Mind-rotting drivel. Incites children to violence and carnal thoughts.\
/coffee|thermos|mug|cup::The newsvendor seems to find his coffee distasteful, though that doesn't stop him drinking it.\
/alley|alleyway::Usually filled with trash and discarded needles.",
"take_taxi|in_taxi|use_taxi|ride_taxi|buy_ride::[[rideTaxi()]]",
"north::tower.south::alley.east::townhouses.west::warehouse"
);

function startCab() {
    if (gs("gotRide") == 0) {
        if (counterSubscribe("cabTicker")) ccount = 0;
    }
}
function cabTicker() {
    
    if (heroloc() == intersection && gs("gotRide") == 0) {
        switch (ccount%10) {
            case 3:
                if (charloc(joey) == intersection) return;
                say("\nA taxi pulls up and idles at the curb.");
                set_charloc(joey, intersection);
                return;
            case 9:
                if (charloc(joey) == nowhere) return;
                say("\nFinding no customers here, the taxi drives away.");
                set_charloc(joey, nowhere);
                return;
        }
    }
    if (gs("gotRide") == 1) {
        counterUnsubscribe("cabTicker");
    }
}
function rideTaxi() {
    if (charloc(joey) == intersection)
        say("The driver eyes you skeptically. \"Yeah? And what're you gonna pay me with, a sermon about the end of the world?\"");
    else
        say("There's no taxi here now.");
}

makePlace("alley",
"ALLEY",
"",
"You are in a dank, deserted alley.  A dumpster looms against one wall, flanked by heaps of reeking garbage.",
"north::The only way out is north, toward a busy intersection.\
/dumpster::There is nothing edible or otherwise useful inside the dumpster today.\
/intersection::It's to your north.\
/uniform::It's hidden in the garbage.\
/garbage|trash|rubbish::[[x_garbage()]]",
"open_dumpster::There is nothing edible or otherwise useful inside the dumpster today.\
/take_garbage::[[take_garbage()]]\
/take_uniform::[[take(uniform.name, 'You wade through the trash and retrieve your uniform from its hiding place.')]]",
"north::intersection",
"out::north"
);
function take_garbage()
{
	if( is_in_inv(uniform) || wearing(uniform) )
	    say("There's nothing else of interest in the garbage.");
	else 
	    say("There's nothing useful in the garbage besides your uniform.");
}
function x_garbage()
{
	if( is_in_inv(uniform) || wearing(uniform) )
        say("There's nothing else of interest in the garbage.");
    else 
        say("Your uniform is carefully concealed under the garbage, where it would never be recognized.");
}

makePlace("tower",
"VEIDT TOWER",
"",
"You are standing at the base of Veidt Tower. It's a concrete and glass colossus over 100 storeys tall, orbited by airships. Through the front doors, you can see a reception desk in an opulent lobby.",
"south::The newspaper stand is several blocks south of here.\
/up|tower|building::The tower is the headquarters of Veidt Industries. Veidt's office will be on the top floor.\
/office::Veidt's office will be on the top floor.\
/airships|airship::One of them looks like a pink elephant.\
/lobby|foyer|hall|in::Marble tiles and velvet ropes and exotic potted plants. Hard to believe Veidt once did honest work.\
/doors|door::The doors are shiny glass, unwelcoming to all but the wealthiest of visitors.\
/desk|receptionist|reception::You'd need an appointment or a profile in [iFortunei] magazine to get past the receptionist.",
"in::[[vlobby()]]\
/climb|climb_tower|up::The tower is completely free from unsightly climbing aids like external fire excapes or drainpipes. There's nothing like a handhold for 50 feet up.\
/talk_receptionist|talk_reception::The receptionist is inside, and you are not.\
/grapple_tower::[[grappleTower()]]",
"south::intersection.in::towerLobby",
""
);
function vlobby() {
    if (wearing(uniform)) {
        say("If you went inside, the receptionist would call the police, not the elevators.");
    } else {
        set_heroloc(towerLobby);
        say("\nThe receptionist takes one look at you and sniffs. \"Oh. You must be lost. I'll just have security show you the way out.\"");
        say("\nTwo large men in suits approach you from either side, but you turn around and exit before you can blow your cover by knocking their heads together.\n");
        set_heroloc(tower);
    }
}
function grappleTower() {
    if (!wearing(uniform)) {
        say("Not while out of uniform. The gun is very distinctive.");
    // } else if (thingmod(grappling_gun) < 1) {
        // say("Your grappling gun is jammed.");
    } else {
        set_heroloc(towerOffice);
    }
}

makePlace("towerLobby",
"VEIDT TOWER - LOBBY",
"",
"You've entered the lobby on the first floor of Veidt Tower. It smells like women's perfume in here, and everything looks very expensive.",
"",
"",
"");

makePlace("towerOffice",
"VEIDT TOWER - OFFICE",
"You fire the grappling gun at the building's lowest ledge, and make your way up the stepped concrete cliff face to a window on the top floor. The gun's hook shatters the glass and catches on the frame, and you haul yourself inside.",
"You are in Adrian Veidt's office on the top floor of Veidt tower. The room is huge, shining and clean like a new glass bottle, and funished with a lot of pretentious art. Veidt's desk stands in the center, framed by sweeping view of the city below.",
"desk::The enormous teak desk supports a computer, a few neat stacks of paper, and several toy figures of famous costumed vigilantes.\
/figures|dolls|toys::Veidt pads his fortune by selling these plastic gimmicks. Among the figures, you recognize Captain Metropolis, both Silk Spectres, your partner Nite Owl, and three different versions of Ozymandias.\
/computer::A \"personal computer\". Another example of Veidt's extravagance.\
/paper|stacks|papers|paperwork::[[x_paperwork()]]\
/ad|crocodile::Bad marketing. Crocodiles are not loveable animals.\
/art::Many of the pieces are incomprehensibly modern, but the others reflect Veidt's obsession with ancient Egypt: animals with human heads, and animal heads on humanoid bodies. You suspect that Veidt too fetishizes deformity.\
/nelly::Gardner looked just about as ineffectual in person as he does in miniature.\
/spectres|sally|laurie::Neither of their costumes are appropriate for children.\
/dan::Daniel did once look that heroic. Too bad.\
/adrian|adrian_toy|adrian_doll::Each of the Ozymandias dolls has a different variation of his purple and gold costume, and a cape made of real cloth.\
/down|city::Veidt can see everything from up here.",
"take_art::It's all too big and heavy to be carrying around. Probably priceless too.\
/take_computer::It's too heavy to carry with you.\
/use_computer|turn_on_computer|turn_computer_on::You have no idea how to use the computer. Anything worth knowing will be in hard copy, anyway.\
/take_ad|take_crocodile::[[take_ad()]]\
/open_desk::Nothing inside but some extra office supplies.\
/take_supplies|take_office_supplies::You don't need them.\
/take_paper|take_papers|take_paperwork::Leave it for Veidt's accountants.\
/take_toys|take_dan|take_laurie|take_silk_spectres|take_adrian::[[take_toys()]]\
/out::You'd probably be caught if you left the office, on camera if not by security.\
/down::[[office_down()]]",
"out::nowhere.down::tower");
function take_ad()
{
    if (take(ad.name, "default")) {
        say("\nYou hear a soft growl, and then a very large furry head pushes open the door. Veidt's mutant cat pads into the room, passes you with a disinterested sniff, and moves to sit in front of the broken window.");
        set_charloc(bubastis, towerOffice);
        sgs("bubu1", 1);
    }
}
function take_toys() {
    var toy = Token[Token.length-1];
    
    if (toy == "adrian" || toy == "laurie" || toy == "sally" || toy == "nelly") {
        say("No thank you.");
    } else if ((toy == "toys" || toy == "dan") && take(laser_pointer.name, "")) {
        say("You pick up the figure of Nite Owl, dislodging a small cylindrical accessory from its arm. Twisting the piece produces a narrow beam of red light. You pocket the laser, and leave the toy.");
    } else {
        say("Dolls are for children.");
    }
}
function x_paperwork()
{
    if (!is_in_inv(ad)) {
        say("The paperwork is mostly dense tables of accounting, except for one sheet with a garish picture of a crocodile. Looks like a mockup for a print advertisement.");
    } else {
        say("None of the other papers on Veidt's desk looks particularly interesting.");
    }
}
function office_down()
{
    if (gs("bubu1") == 1) {
        say("Bubastis is sitting in front of the window. You try to sneak past, but she bats you away with one huge paw. Luckily for you, it seems like she just wants to play.");
    } else
        set_heroloc(tower);
}

makePlace("townhouses",
"DANIEL'S STREET",
"",
"[[move_dan()]]You are on tree-lined street, between rows of stately brownstone townhouses.",
"north::Daniel's house is to the north.\
/west::The newspaper stand is several blocks west of here.\
/house|houses|townhouse|townhouses|brownstone|brownstones|street::This is one of the wealthier neighborhoods in the city. The buildings are old and relatively clean. Daniel's house is to the north, distinguished from the rest by the shiny new lock on its door.\
/lock::It might be new, but you doubt it's very durable.",
"lockpick_door|open_door::[[lockpick_dansdoor()]]",
"north::danshouse1.west::intersection",
"in::north"
);
function lockpick_dansdoor()
{
	if( Token[ Token.length-1 ] == "door" || Token[ Token.length-1 ] == "house" )
            say("Daniel must be getting careless: his front door is already unlocked.");
        else if( Token.length == 1 )
            say("Pick the lock on what?")
        else
            say("That doesn't have a lock you can pick.");
}
function move_dan()
{
    if (charloc(dan) == nest && is_in_inv(grappling_gun))
        set_charloc(dan, danshouse1);
}

makePlace("danshouse1",
"DANIEL'S HOUSE - MAIN FLOOR",
"[[ccount = 0;]]You're about to kick the door in when you notice it's already unlocked.  That's unusual.",
"[[x_danshouse1()]]You are in Daniel Dreiberg's living room. Bookshelves line the walls, and owl-themed fripperies abound. It's just as you remember it.",
"south::That's the front door.\
/up::A staircase leads up to the second floor.\
/bookshelves::The shelves contain a lot of well-thumbed nature journals, technical manuals, and historical adventure stories.\
/books::The shelves contain a lot of well-thumbed nature journals, technical manuals, and historical adventure stories.\
/decor|owls|fripperies::This could be the home of a demented old woman.",
"take_books|take_book::You don't have time for recreational reading.\
/take_owls|take_fripperies|take_knickknacks|take_lampshade|take_shakers|take_clock|take_coasters|take_coaster::No thank you.",
"south::townhouses.upstairs::danshouse2",
"out::south.up::upstairs"
);
function x_danshouse1()
{ 
    if (gs("danfree") == 0 || charloc(dan) == danshouse2)
        counterSubscribe("danTicker");
    // else if (charloc(dan) == heroloc()) {
    else if (thingmod(grappling_gun) > 0) {
        if (danshouse1.exits.indexOf("downstairs") < 0) {
            danshouse1.exits += ".downstairs::nest";
            danshouse1.hExits += ".down::downstairs";
        }
    }
}
function danTicker()
{    
    if (heroloc() == danshouse1 && gs("danfree") == 0) {
        if (ccount%7 == 0) 
            say("\nYou can hear Daniel's voice calling faintly from upstairs: \"Hello?  Help!\"");
        if (ccount%7 == 3) 
            say("\n\"Is somebody down there? Help!\"");
    }
    if (gs("danfree") == 1) {
        if (heroloc() == danshouse2) {
            ccount = 0;
            return;
        }
    
        if (ccount%5 == 4) {
            if (heroloc() == danshouse1)
                say("\nDaniel comes downstairs, fully dressed and looking sheepish.");
    
            counterUnsubscribe("danTicker");
            set_charloc(dan, danshouse1);
            set_talkindex(dan, 99);
        }
    }
}

makePlace("danshouse2",
"DANIEL'S HOUSE - BEDROOM",
"You open the bedroom door to the sight of Daniel in an extremely compromising position.",
"This is Daniel's bedroom. It looks comfortable, with thick carpet and patterned wallpaper. There's a large feather bed, and a hardwood closet against one wall.",
"down::The stairs lead down to the first floor.\
/handcuffs::[[bedroomX('handcuffs')]]\
/carpet|bed|closet|wallpaper|decor::Self-indulgent luxuries. Daniel is very wealthy.\
/undergarments|underwear|panties::[[bedroomX('undergarments')]]",
"lockpick_handcuffs|lockpick_cuffs::[[freeDan()]]\
/free_dan|unlock_dan|help_dan::How?\
/open_closet::[[dansCloset()]]",
"downstairs::danshouse1",
"down::downstairs"
);
function freeDan() {    
    var txt = "You set to work picking the locks on the handcuffs, while keeping your eyes safely averted from Dreiberg's underdressed form..."    
    txt += "\n\n\"Thanks!  I don't know how long I would've been stuck there if you hadn't shown up...I'm just gonna get dressed, okay?  I'll be downstairs in a minute.\"\n"    
    txt += "\nYou leave quickly.\n";    
    say(txt);
    
    set_talkindex(dan, 3);    
    ccount = 0;    
    sgs("danfree", 1);    
    set_heroloc(danshouse1);
}
function dansCloset()
{
    if (charloc(dan) == heroloc()) {
        say("Inspections of Daniel's effects are best done when he's not around, or not awake.");
        return;
    }
    
    if (danshouse2.sights.indexOf("cardigans") == -1) {
        danshouse2.sights += "/cardigans|sweaters::Daniel likes cardigans./porn::\"RANDY REDHEADS...INSATIABLE GINGERS IN FULL COLOR!!\"...This is disgusting. You've seen enough.";
        danshouse2.special += "/take.porn::You'll confiscate it, to preserve Daniel's virtue.";
    }
    
    say("You make a careful study of the contents of Dreiberg's closet. It contains a lot of mothballs, cardigans, and...pornography.");
}
function bedroomX(x) {

    if (charloc(dan) == heroloc()) {
        x += "0";
    }

    switch (x) {
        case "handcuffs0":
            say("They are an insult to everything.");
            break;
        case "undergarments0":
            say("You'd rather not.");
            break;
        case "handcuffs":
        case "undergarments":
            say("Fortunately, you don't see them.");
    }
}

makePlace("nest",
"OWL'S NEST",
"",
"The Owl's Nest is Daniel's secret basement workshop, which saw more frequent use before he retired. There are tools and dismembered machinery strewn all around the room, and the hulking round shape of the owlship looms against the back wall. Everything is very dusty.",
"archie::The owlship Archie is hooded and dormant, sitting on blocks under a tarp.\
/machinery::Daniel built many ingenious devices for catching criminals, including the owlship and your grappling gun. Some were never completed, and some were completely inffective, left to salvage for future projects.\
/tools::The tools range in size from an awl to a bandsaw. There are many whose purpose you can't even guess at. You can recognize a crowbar, at least.\
/crowbar::It's lying on the floor.",
"upstairs::danshouse1",
"up::downstairs"
);

makePlace("rockefeller1",
"ROCKEFELLER MILITARY RESEARCH CENTER - EXTERIOR",
"",
"You are outside the heavily guarded home of Dr. Manhattan. The complex is surrounded by high security fences topped with razor wire.",
"taxi::The cab driver is waiting for you.\
/north::The main gate is to your north.\
/boxes::You sneak around the side of the delivery van and inspect the boxes being unloaded. The packing slip on the largest crate says \"SPORTS EQUIPMENT\".\
/crate::It's a wooden crate about the size of a minifridge.",
"north::There are armed guards at the gate, and you'd be lucky if all they did was turn you away.",
"in::north"
);

makePlace("crate",
"CRATE",
"",
"You are inside a small wooden box. It's dark.",
"out::You have no idea what's outside, but you'd better be ready to fight.",
"",
"out::rockefeller2"
);

makePlace("rockefeller2",
"ROCKEFELLER MILITARY RESEARCH CENTER - LABORATORY",
"",
"You are in a sterile, cavernous room full of mysterious equipment. The floors are metal, and the walls are metal",
"out::It might be difficult to get out of here without being seen...",
"",
"out:rockefeller1"
);

makePlace("warehouse",
"DOCK WAREHOUSE",
"You make your way into one of the waterfront warehouses, surprising a pack of truant children when you kick the door down. They flee at the sight of you, leaving behind some comic books and half-smoked cigarettes.",
"You are in a dim, abandoned warehouse, full of dust and rotten pallets. Some children have left their garbage on the floor here: cigarettes and candy wrappers and stolen comic books.",
"comic|comics|books::Mostly the usual lurid swill that children read these days. One of the books looks like it was written in marker pen.\
/pallets|dust::Nothing here is worth anything, or it would have been lifted long ago.\
/garbage|cigarettes::The spoils of shoplifting.\
/handwritten_book::It seems to have been hand-written on letter paper.",
"take_book::[[take(handwritten_book.name, 'default')]]",
"east::out",
"out::intersection"
);


function places_loaded()
{	var HTMLOut = document.getElementById("outDiv").innerHTML;

	HTMLOut += "places loaded!" + "<br>";
	document.getElementById('outDiv').innerHTML = HTMLOut;
	
	document.getElementById('textIn').focus();
}